//Net.h

#pragma once

#ifndef NET_H_INCLUDED
#define NET_H_INCLUDED

#include "stdafx.h"
#include "World.h"

class Net
{
public:
	Net();
	~Net();

	//Our protocol
	struct Msg
	{
		byte m_yType;
	};

	struct WorldMsg : public Msg
	{
		dword m_iPacketID;
		byte m_iNumberOfPlayers;

		dword m_iIPAddr;
		float m_fPositionX;
		float m_fPositionY;
		float m_fRotation;
		float m_fVelocityX;	
		float m_fVelocityY;
		float m_fAccelerationX;
		float m_fAccelerationY;
		float m_fThrust;		
		float m_fSteering;	

		int m_dwScore;	

		float m_fGemPosX;		
		float m_fGemPosY;
		dword m_dwGemID;
	};

	enum
	{
		GamePort = 1236,
		MaxBufferSize = 2048,
		TimeOut = 10000,
		MT_Ping = 1,
		MT_Pong = 2,
		MT_Quit = 3,
		MT_WorldMsg = 4
	};

	bool Init(World* pWorld);
	void Shut();

	void Scan();
	void ScanExternals();
	void Recv();

	void Broadcast();

	void HandleMsg(IPAddr& xFrom, WorldMsg& xMsg);
	void FillMsg(int idx, WorldMsg* p_xMsg);

	bool m_bIsRunning;
	World* m_pxWorld;
	UdpSocket m_xSock;
	IPAddr m_xLocal;

	byte* m_aiBuffer;

};

#endif
